import Vue from "vue"

export default{
    namespaced: true,
    state:()=>({
        shoplist:[],
    }),
    // getters: {
    //     allinfo(state){//同级总计信息
    //         let allNum = 0
    //         let allPrice=0
    //         let allcheck=true //全选状态
    //         let checknum=0
    //         let checkprice=0
    //         for(let i=0;i<state.length;i++){
    //             allPrice+=state[i].price
    //         }
    //         return {allNum,allPrice,allcheck,checknum,checkprice}
    //     }
    // },
    mutations: {
        getcart(state,obj){
            let {shoplist} = state
            for(let i=0;i<shoplist.length;i++){
                if(shoplist[i].id==obj.id){
                    shoplist[i].spec_type++
                    return
                }
            }
            state.shoplist.push(obj)
        },
        cartnummut(state,{idx,bool}){ 
            let {spec_type} = state.shoplist[idx]
            if(bool){
                state.shoplist[idx].spec_type++
            }else{
                spec_type>0? state.shoplist[idx].spec_type-- : ''
                if(state.shoplist[idx].spec_type==0){
                    state.shoplist.splice(idx,1)
                }
            }
        },

    },

}